package com.zx.pm.modules.zx.web;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zx.pm.common.web.BaseController;
import com.zx.pm.modules.zx.entity.Lzd;
import com.zx.pm.modules.zx.entity.MakeTender;
import com.zx.pm.modules.zx.entity.ProExperts;
import com.zx.pm.modules.zx.entity.ProSupplier;
import com.zx.pm.modules.zx.entity.ProTimeNode;
import com.zx.pm.modules.zx.entity.TenderFile;
import com.zx.pm.modules.zx.entity.TenderSection;
import com.zx.pm.modules.zx.service.BidBondService;
import com.zx.pm.modules.zx.service.LzdService;
import com.zx.pm.modules.zx.service.MakeTenderService;
import com.zx.pm.modules.zx.service.ProExpertsService;
import com.zx.pm.modules.zx.service.ProTimeNodeService;
import com.zx.pm.modules.zx.service.TenderFileService;
import com.zx.pm.modules.zx.service.TenderRequireService;
import com.zx.pm.modules.zx.service.TenderSectionService;

@Controller
@RequestMapping(value = "${adminPath}/zx/all/lzd")
public class LzdAllInfoController extends BaseController{

	@Autowired
	private LzdService lzdService;
	
	@Autowired
	private TenderRequireService tenderRequireService;
	 
	@Autowired
	private MakeTenderService makeTenderService;
	
	@Autowired
	private TenderFileService tenderFileService;
	
	@Autowired
	private ProTimeNodeService proTimeNodeService;
	
	@Autowired
	private TenderSectionService tenderSectionService;
	
	@Autowired
	private ProExpertsService proExpertsService;
	
	@Autowired
	private BidBondService bidBondService;
	
	@RequestMapping(value = "getLzdAllInfo")
	public String getLzdAllInfo(String lzdId, Model model, String pageFlag, String sectionId) {
		// 获取项目基本信息
		Lzd lzd = lzdService.get(lzdId);
		lzd.setSectionId(sectionId);
		// 获取单个标段信息
		TenderSection ts = tenderSectionService.get(sectionId);
		// 获取项目标段信息
		//lzd.setSectionList(tenderSectionService.getSectionListByLzdId(lzdId, null));
		List<TenderSection> sectionList = new ArrayList<TenderSection>();
		sectionList.add(ts);
		lzd.setSectionList(sectionList);
		
		
		lzd.settRequire(tenderRequireService.getByLzdId(lzdId));
		// 获取标书制作信息
		MakeTender mtParm = new MakeTender();
		mtParm.setLzdId(lzdId);
		mtParm.setSectionId(sectionId);
		List<MakeTender> mtList = makeTenderService.getList(mtParm);
		if(mtList != null && mtList.size() > 0) {
			for(MakeTender e : mtList) {
				// 获取标书文件
				TenderFile t = new TenderFile();
				t.setLzdId(lzdId);
				t.setMakeTenderId(e.getId());
				e.setFileList(tenderFileService.findList(t));
			}
			
		}
		// 获取项目时间节点
		ProTimeNode parmPt = new ProTimeNode();
		parmPt.setLzdId(lzdId);
		parmPt.setSectionId(sectionId);
		ProTimeNode pt = proTimeNodeService.get(parmPt);
		// 项目评审专家
		ProExperts p = new ProExperts();
		p.setLzdId(lzd.getId());
		p.setSectionId(lzd.getSectionId());
		List<ProExperts> peList = proExpertsService.findListByLzdId(p);
		// 项目供应商及投标保证金
		ProSupplier ps = new ProSupplier();
		ps.setLzdId(lzd.getId());
		ps.setSectionId(lzd.getSectionId());
		// 获取项目供应商信息
		List<ProSupplier> psList = bidBondService.findPayBidBondList(ps);
		
		model.addAttribute("lzd", lzd);
		model.addAttribute("mtList", mtList);
		model.addAttribute("pt", pt);
		model.addAttribute("peList", peList);
		model.addAttribute("psList", psList);
		model.addAttribute("pageFlag", pageFlag);
		model.addAttribute("ts", ts);
		return "modules/zx/lzdAllInfo";
	}
	
}
